package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: shaki
 * @Date: 2021/6/24 14:50
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Resource
    private EduTeacherService teacherService;

    @Resource
    private EduCourseService courseService;

    /**
     * 前端分页查询讲师
     */
    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable("page") long page, @PathVariable("limit") long limit){
        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        Map<String,Object> map= teacherService.getTeacherFrontList(teacherPage);
        return R.ok().data(map);
    }

    /**
     * 讲师详情
     */
    @GetMapping("/getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable("id") String id){
        EduTeacher eduTeacher = teacherService.getById(id);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
